# -*- coding:utf-8 -*-
from dao.MySqlDAL import MySqlDAL
import datetime
from service.stock_price import stockprice
__author__ = 'shudongma.msd(风骐)'

'''
补上 股市休市时的价格为其前一个交易日的价格
'''

sqlUtil = MySqlDAL()

start_date = datetime.datetime.strptime('2015-10-01', "%Y-%m-%d").date()
# end_date = datetime.date.today()
end_date = datetime.datetime.strptime('2016-02-22', "%Y-%m-%d").date()

while start_date <= end_date:
    if stockprice.isRestDay(str(start_date)):
        res = sqlUtil.get_dimensions_rows("SELECT * FROM tb_stock_price WHERE date='"+str(start_date)+"'")
        if len(res) == 0:
            tmpdate = start_date - datetime.timedelta(days=1)
            sql = "INSERT INTO tb_stock_price(stock_id,price,percent,open,updown,yestclose,volume,turnover," \
                  "turnover_rate,pe_lyr,pe_ttm,pb,mr,date,update_time) SELECT stock_id,price,percent,open,updown,yestclose,volume,turnover," \
                  "turnover_rate,pe_lyr,pe_ttm,pb,mr,'"+str(start_date)+"',0 FROM tb_stock_price " \
                  "WHERE date='"+str(tmpdate)+"'"
            print sqlUtil.execute_sql(sql)
    start_date = start_date + datetime.timedelta(days=1)

